import React from 'react';
import { connect } from 'dva'

import moment from 'moment'
import MyDatePicker from 'components/MyDatePicker'

import WaterStatistics from './WaterStatistics'
import StatisticsBar from './StatisticsBar'
import StatisticsPie from './StatisticsPie'

const nowTimeStamp = Date.now();
const now = new Date(nowTimeStamp);
const time = moment(now).format('YYYY')

@connect(({ business }) => ({ ...business }))
class Statistics extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      time
    }
  }

  // change
  handleChange = (data) => {
    const lastTime = this.state.time;
    const time = moment(data).format('YYYY')
    if (lastTime === time) {
      return;
    }
    this.setState({
      time
    })
  }

  render() {
    const { time } = this.state;
    return (<>
      <MyDatePicker
        defaultValue={time}
        onChange={this.handleChange}
      />
      <WaterStatistics
        defaultValue={time}
      />
      <StatisticsBar
        defaultValue={time}
      />
      <StatisticsPie
        defaultValue={time}
      />
    </>)
  }
}

export default Statistics;
